1
The Shift to Reactive Programming
AI033 Lesson 17
00:00

The shift to Reactive Programming represents a fundamental transition from imperative, pull-based logic to a declarative, push-based paradigm centered on asynchronous data streams. It is a direct response to the inefficiencies of traditional "thread-per-request" models.

1. Moving Beyond Blocking I/O

In traditional systems, threads often sit idle—wasting CPU resources—while waiting for responses from databases or remote APIs. Reactive programming adopts an event-driven architecture where the application reacts to signals (data, errors, or completion) as they occur.

2. Data-at-Rest vs. Data-in-Motion

Instead of describing how to perform steps sequentially, developers define what should happen when an event travels through a stream. Changes propagate automatically through the system.

Figure 17.2: Thread Utilization vs. Blocking I/OStream 1Stream 2Stream 3Thread 1 (Switching)Thread 2 (Blocked)Locked I/OUnprocessed

As shown above, when Thread 2 enters a Blocking I/O state (shaded red), it cannot yield, preventing Stream 3 from being processed even though the thread is technically "assigned."

main.py
TERMINAL bash — 80x24
> Ready. Click "Run" to execute.
>